function [data,data_trans] = generate_data_weitz_categ(N,J,supp_z,alpha,beta,mu_c,sigma_c)

x = rand(N,J);
z = supp_z(randi(length(supp_z),N,J));

c = exp(randn(N,1)*sigma_c + mu_c);
epsilon = -evrnd(0,1,[N,J]);

% get arrays for reservation value calculation
RHS = NaN(length(supp_z),1);
for rr=1:length(supp_z)
    vec_prob = 1/length(supp_z)*ones(1,length(supp_z));
    vec_diff = max(supp_z - supp_z(rr),0);
    RHS(rr) = sum(vec_prob.*vec_diff);
end

choice = zeros(N,1);
choice_seq = zeros(N,1);
open = zeros(N,J);

for i=1:N
       
    c_temp = c(i);
    
    % get reservation value in units of z (same for all j)
    [~,ind(i)] = min(abs(RHS-c_temp/beta));
    reserve_z_temp = supp_z(ind(i));
    
    delta_armstrong_temp = alpha*x(i,:) + beta*min(z(i,:),reserve_z_temp) + epsilon(i,:);
    
    [~,choice(i)] = max(delta_armstrong_temp,[],2);
    
    % get which boxes are opened
    delta_prior_temp = alpha*x(i,:) + epsilon(i,:);
    [~,ind_sort] = sort(delta_prior_temp,'descend');
    
    delta_full_temp = alpha*x(i,:) + beta*z(i,:) + epsilon(i,:);
    delta_prior_reserve_temp = alpha*x(i,:) + beta*reserve_z_temp + epsilon(i,:);
    
    j = 1;
    temp_search = 1;
    while j<=J-1 && temp_search==1
        
        temp_ind = ind_sort(j);
        open(i,temp_ind) = 1;
        
        temp_u_inhand = max(delta_full_temp(logical(open(i,:))));
        
        temp_search = (temp_u_inhand<delta_prior_reserve_temp(ind_sort(j+1)));
        j = j+1;
        
    end
    
    if j==J && temp_search==1
        open(i,ind_sort(J)) = 1;
    end
    
    % check
    [~,max_temp] = max(delta_full_temp(logical(open(i,:))));
    ind_temp = find(open(i,:));
    choice_seq(i) = ind_temp(max_temp);
            
end

data.x = x;
data.z = z;
data.c = c;
data.epsilon = epsilon;
data.choice = choice;
data.open = open;
% data.y = zeros(size(choice));
% data.y(choice==1) = 1;

data = struct2dataset(data);

data_trans = transform_data_nonorm(data,J);

end

